package cn.edu.swu.gyt;

import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args)throws SQLException {
        DatabaseService service=new DatabaseService();
        service.init();

        List<Book> books= service.query("select * from books",new BookResultSetVisitor());
        books.forEach(b->{
            System.out.println(b.getAuthor());
        });

        //匿名类
        List<String> names=service.query("select name from books", new ResultSetVisitor() {
            @Override
            public List visit(ResultSet rs) throws SQLException {
                List<String> names=new ArrayList<>();
                while (rs.next()){
                    names.add(rs.getString("name"));
                }
                return names;
            }
        });
        names.forEach(n->{
            System.out.println(n);
        });

    }
}
